<?php

function reequipment_adminapi_createfrequency($args)
{
    extract($args);

    // Argument check - make sure that all required arguments are present,
    // if not then set an appropriate error message and return
    $invalid = array();
    if (!isset($frequency) || !is_string($frequency)) {
        $invalid[] = 'area_name';
    } 
    if (count($invalid) > 0) {
        $msg = xarML('Invalid #(1)', join(', ', $invalid));
        xarErrorSet(XAR_SYSTEM_EXCEPTION, 'BAD_PARAM', new SystemException($msg));
        return;
    } 
    
    // Get datbase setup
    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $table = $xartable['refrequency'];
    // Get next ID in table
    $nextId = $dbconn->GenId($table);

    // Add item
    $query = "INSERT INTO $table ("
        . " frequency_id, frequency )"
        . " VALUES (?, ?)";
    $result =& $dbconn->Execute($query, array($nextId, $frequency));
    if (!$result) return;
    // Get the ID of the item that we inserted
    $id = $dbconn->PO_Insert_ID($table, 'frequency_id');

    // Return the id of the newly created link to the calling process
    return $id;
}
?>